package com.penton.util.widget;

import android.content.Context;
import android.util.Log;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.widget.TextView;

/**
 * 显示歌词 http://hi.baidu.com/wishwingliao/blog/item/66488135e8fe290690ef3901.html
 * @author pengjianbo <pengjianbosoft@gmail.com>
 *
 */
public class LyricTextView extends TextView{
	 private float mTouchStartX;
	    private float mTouchStartY;
	    private float x;
	    private float y;
	    
	    private WindowManager wm=(WindowManager)getContext().getApplicationContext().getSystemService("window");
	    private WindowManager.LayoutParams wmParams ;// ((MyApplication)getContext().getApplicationContext()).getMywmParams();

	    public LyricTextView(Context context) {
	        super(context);        
	    }
	    
	     @Override
	     public boolean onTouchEvent(MotionEvent event) {        
	         //获取相对屏幕的坐标，即以屏幕左上角为原点    
	         x = event.getRawX();
	         y = event.getRawY()-25;   //25是系统状态栏的高度
	         Log.i("currP", "currX"+x+"====currY"+y);
	         switch (event.getAction()) {
	                //手指按下时
	            case MotionEvent.ACTION_DOWN:
	                //获取相对View的坐标，即以此View左上角为原点
	                mTouchStartX =  event.getX();  
	                mTouchStartY =  event.getY();               
	                Log.i("startP", "startX"+mTouchStartX+"====startY"+mTouchStartY);                
	                break;
	                //手指移动时
	            case MotionEvent.ACTION_MOVE:
	                //更新视图
	                updateViewPosition();
	                break;
	                //手指松开时
	            case MotionEvent.ACTION_UP:
	                updateViewPosition();
	                mTouchStartX=mTouchStartY=0;
	                break;
	            }
	            return true;
	        }    
	     private void updateViewPosition(){
	        //更新浮动窗口位置参数
	        wmParams.x=(int)( x-mTouchStartX);
	        wmParams.y=(int) (y-mTouchStartY);
	        wm.updateViewLayout(this, wmParams);
	     }
	}